package fr.gestproj.model;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.persistence.annotations.Index;
import org.springframework.security.core.GrantedAuthority;

/**
 *
 * @author Anne
 */
@Entity
@Table(name = "role")
public class Role implements Serializable, GrantedAuthority {

    @Id
    @Column(name = "code")
    private String code;

    @Index
    @Size(max = 100)
    @NotNull
    @Column(name = "libelle", length = 100, nullable = false)
    private String libelle;

    @Size(max = 255)
    @Column(name = "description", length = 255, nullable = true)
    private String description;

    @Override
    public String getAuthority() {
        return code;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getLibelle() {
        return libelle;
    }

    public void setLibelle(String libelle) {
        this.libelle = libelle;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (code != null ? code.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Role)) {
            return false;
        }
        Role other = (Role) object;
        if ((this.code == null && other.code != null) || (this.code != null && !this.code.equals(other.code))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "fr.gestproj.model.Role[ code=" + code + " ]";
    }

}
